package com.eliza.springboot.v3.http.client

import com.eliza.springboot.v3.repository.entity.Song
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.client.RestTemplate


@RestController
internal class MessageRestController(restTemplateBuilder: RestTemplateBuilder) {
    private val restTemplate: RestTemplate = restTemplateBuilder.build()

    @RequestMapping("/client/{id}")
    fun getMessage(@PathVariable("id") id: Long): String {
        val person: Song? = restTemplate.getForObject(
            "http://192.168.20.5:8080/database/getById/1",
            Song::class.java, id
        )
        return "Hello " + person?.title
    }
}